package com.goodluck.goodluckim.sdk.dispatcher;

import com.goodluck.goodluckim.sdk.constant.MsgActions;
import com.goodluck.goodluckim.sdk.dispatcher.strategy.DefaultMessageStrategy;
import com.goodluck.goodluckim.sdk.dispatcher.base.IMessageStrategy;
import com.goodluck.goodluckim.sdk.dispatcher.strategy.MessageReceiveStrategy;
import com.goodluck.goodluckim.sdk.dispatcher.strategy.MessageStatusChangeStrategy;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by wyj on 2018/10/23.
 */

public class MessageDispatcherFactory {
    private Map<String, IMessageStrategy> actionToClass = new HashMap<>();
    private static final String DEFAULT_ACTION = "default_action";

    public MessageDispatcherFactory() {
        actionToClass.put(DEFAULT_ACTION, new DefaultMessageStrategy());
        actionToClass.put(MsgActions.SC_MESSAGE_RESULT, new MessageReceiveStrategy());
        actionToClass.put(MsgActions.SC_MESSAGE_STATUS_CHANGE, new MessageStatusChangeStrategy());
    }

    /**
     * 创建action对应的消息解析处理类
     *
     * @param action
     * @return
     */
    public IMessageStrategy createMessageStrategy(String action) {
        IMessageStrategy messageStrategy = actionToClass.get(action);
        if (messageStrategy == null) {
            messageStrategy = actionToClass.get(DEFAULT_ACTION);
        }
        return messageStrategy;
    }
}
